package com.chookss.mine.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.base.StaticClass;
import com.chookss.home.NavigationBaseActivity;
import com.chookss.home.document.MyDocumentActivity;
import com.chookss.home.interview.InterviewRecordsActivity;
import com.chookss.home.knowledge.LookListActivity;
import com.chookss.home.knowledge.ScoreRankActivity;
import com.chookss.home.knowledge.UploadListActivity;
import com.chookss.home.publish.PublishLogsActivity;
import com.chookss.home.publish.PublishNewsActivity;
import com.chookss.home.tuwen.MyTuwenActivity;
import com.chookss.home.workbench.WorksActivity;
import com.chookss.mine.entity.MineNavigationEntity;
import com.chookss.mine.personal.MyLogActivity;
import com.chookss.mine.personal.MyLongVedioActivity;
import com.chookss.mine.personal.MyLongVediosActivity;
import com.chookss.mine.personal.MyNewsActivity;
import com.chookss.mine.personal.MyVedioActivity;
import com.chookss.mine.personal.MyVediosActivity;
import com.chookss.tiku.MyErrorSubjectActivity;
import com.chookss.tools.MyEvent;
import com.johnrambo.ktea.ktExtends.ShareUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.annotations.Nullable;

public class MineAdapter extends BaseQuickAdapter<MineNavigationEntity, BaseViewHolderEx> {
    private Context mContext;
    private int width, height;
    private String employeeCode;

    public MineAdapter(int layoutResId, Context context, @Nullable List<MineNavigationEntity> data) {
        super(layoutResId, data);
        this.mContext = context;
        employeeCode = new ShareUtils().getString(mContext, StaticClass.EMPLOYEECODE, "");
    }

    public void setEmployeeCode(String employeeCode) {
        this.employeeCode = employeeCode;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, MineNavigationEntity item) {
        TextView tvTitle = helper.getView(R.id.tvTitle);
        ImageView ivLogo = helper.getView(R.id.ivLogo);
        tvTitle.setText(item.getTitle());
        Glide.with(mContext).load(item.getLogo()).into(ivLogo);
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (Urls.antiShake.check()) {
                    return;
                }
                Intent intent = null;
                if (tvTitle.getText().toString().equals("小视频")) {
                    intent = new Intent(mContext, MyVedioActivity.class);
                    intent.putExtra("employeeCode", employeeCode);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("视频")) {
                    intent = new Intent(mContext, MyLongVedioActivity.class);
                    intent.putExtra("employeeCode", employeeCode);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("日志")) {
                    intent = new Intent(mContext, MyLogActivity.class);
                    intent.putExtra("employeeCode", employeeCode);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("资料")) {
                    intent = new Intent(mContext, MyDocumentActivity.class);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("集合")) {
                    intent = new Intent(mContext, MyVediosActivity.class);
                    intent.putExtra("employeeCode", employeeCode);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("课程")) {
                    intent = new Intent(mContext, MyLongVediosActivity.class);
                    intent.putExtra("employeeCode", employeeCode);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("新闻")) {
                    intent = new Intent(mContext, MyNewsActivity.class);
                    intent.putExtra("employeeCode", employeeCode);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("学习计划")) {
                    String code1 = new ShareUtils().getString(mContext, StaticClass.BOTTOM_1_CODE, "");
                    String code3 = new ShareUtils().getString(mContext, StaticClass.BOTTOM_3_CODE, "");
                    if ("04".equals(code1) || "04".equals(code3)) {
                        Map<String,String> map=new HashMap<>();
                        map.put("HomeBottom","Xuexijihua");
                        map.put("code","04");
                        EventBus.getDefault().post(new MyEvent(map));
                    } else {
                        intent = new Intent(mContext, NavigationBaseActivity.class);
                        intent.putExtra("type", 4);
                        mContext.startActivity(intent);
                    }
                } else if (tvTitle.getText().toString().equals("错题本")) {
                    intent = new Intent(mContext, MyErrorSubjectActivity.class);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("审核")) {
                    intent = new Intent(mContext, WorksActivity.class);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("写日志")) {
                    intent = new Intent(mContext, PublishLogsActivity.class);
                    intent.putExtra("type", 3);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("写周报")) {
                    intent = new Intent(mContext, PublishLogsActivity.class);
                    intent.putExtra("type", 1);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("写月报")) {
                    intent = new Intent(mContext, PublishLogsActivity.class);
                    intent.putExtra("type", 2);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("发新闻")) {
                    intent = new Intent(mContext, PublishNewsActivity.class);
                    mContext.startActivity(intent);
                } else if (tvTitle.getText().toString().equals("面试评价")) {
                    intent = new Intent(mContext, InterviewRecordsActivity.class);
                    intent.putExtra("type", 2);
                    mContext.startActivity(intent);
                }else if (tvTitle.getText().toString().equals("图文")) {
                    intent = new Intent(mContext, MyTuwenActivity.class);
                    mContext.startActivity(intent);
                }else if (tvTitle.getText().toString().equals("排行榜")) {
                    intent = new Intent(mContext, ScoreRankActivity.class);
                    mContext.startActivity(intent);
                }else if (tvTitle.getText().toString().equals("最近上传")) {
                    intent = new Intent(mContext, UploadListActivity.class);
                    mContext.startActivity(intent);
                }else if (tvTitle.getText().toString().equals("最近浏览")) {
                    intent = new Intent(mContext, LookListActivity.class);
                    mContext.startActivity(intent);
                }else if (tvTitle.getText().toString().equals("图库")) {
                    intent = new Intent(mContext, NavigationBaseActivity.class);
                    intent.putExtra("type", 26);
                    intent.putExtra("roleType", 0);
                    mContext.startActivity(intent);
                }
            }
        });
    }

}
